home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / LZAPI.ZIP / LZRES.ZIP / LZDIB.CPP next >
Encoding:
C/C++ Source or Header  |  1995-03-30  |  4.5 KB  |  155 lines

  1. /* LZDIB.CPP ---------------------------------------------------*
  2.  * L Z D I B --- Implementation OWL 2.x - Support for              *
  3.  *         LHA-Compressed Bitmaps                *
  4.  * (C) 1995 Dipl. Ing. Bernd herd Dipl. Ing. Herald Nuding    *
  5.  * Heidelberger Landstr. 316 D-64297 Darmstadt, 0049-6151-591216*
  6.  *--------------------------------------------------------------*/
  7. #define STRICT
  8.  
  9. #include <owl\owlpch.h>
  10. #pragma hdrstop
  11.  
  12. #include "lzdib.h"
  13.  
  14.  
  15. /* IMPLEMENTS:
  16.    TLZDib        derived from TDib
  17.    TLZBitmap                         TBitmap
  18. */
  19.  
  20.  
  21. /* -------------------------------------------------------------*
  22.  * Constructors for TLZDib                    *
  23.  *--------------------------------------------------------------*/
  24.  
  25. /* TLZDib is a Class derived from TDib that brings with it new construtors:
  26.  
  27.    TLZDib(HINSTANCE instance, TResID resID, const char *NameInArchiv=NULL);
  28.  
  29.       A TLZDib-Object constructed with this constructor will load
  30.       a LZH-Compressed BMP-File from the Archiv.
  31.  
  32.    TLZDib(LPLZHEAD SourcePtr, const char *NameInArchiv=NULL);
  33.  
  34.       A TLZDib-Object constructed with this constructor will decompress
  35.       the memory-Block "SourcePtr" and create a TDib-Object for it
  36. */
  37.  
  38.  
  39.  
  40.  
  41. // ---- TLZDib from Resource -----------------------------
  42.  
  43. TLZDib::TLZDib(HINSTANCE Instance, TResId resID, const char *NameInArchiv)
  44.     :TDib( GimmeADibHandle( Instance, resID, NameInArchiv ), AutoDelete )
  45. //    :TDib ( LoadLZHResource(instance, resID, NameInArchiv, sizeof(BITMAPFILEHEADER) ), AutoDelete )
  46. { // that's all - Folks!
  47. }
  48.  
  49.  
  50.  
  51. // ---- TLZDib from Memory Block -------------------------
  52.  
  53. TLZDib::TLZDib(LPLZHEAD SourcePtr, const char *NameInArchiv)
  54.     :TDib ( DecompressLZH(SourcePtr, NameInArchiv, sizeof(BITMAPFILEHEADER) ), AutoDelete )
  55. { // that's all - Folks!
  56. }
  57.  
  58.  
  59.  
  60. // ---- Get a Handle, depending if Archiv is found -------
  61. HGLOBAL TLZDib::GimmeADibHandle(HINSTANCE Instance, TResId resID, const char *NameInArchiv)
  62. { HGLOBAL returnvalue;
  63.  
  64.   // ---- First test if we have a LZH-Archiv ---------------
  65.   returnvalue = LoadLZHResource(Instance, resID, NameInArchiv, sizeof(BITMAPFILEHEADER) );
  66.  
  67.   // ---- If this did not work, try the normal BITMAP type--
  68.   if (!returnvalue) {
  69.     HRSRC   hfnd;
  70.     HGLOBAL hres,   hdest;
  71.     LPSTR   source,  dest;
  72.     DWORD   Size;
  73.  
  74.     if ( NULL != (hfnd  = FindResource( Instance, resID , RT_BITMAP )) &&
  75.      0L   != (Size  = SizeofResource( Instance, hfnd)) &&
  76.      NULL != (hdest = GlobalAlloc( GHND, Size ) ) &&
  77.      NULL != (hres  = ::LoadResource( Instance, hfnd )) &&
  78.      NULL != (source= (LPSTR) LockResource( hres )) &&
  79.      NULL != (dest  = (LPSTR) GlobalLock( hdest )) ) {
  80.  
  81.      hmemcpy(dest, source, Size);
  82.  
  83.      GlobalUnlock(hdest);
  84.      UnlockResource(hres);
  85.      returnvalue = hdest;
  86.     }
  87.   }
  88.  
  89.   return returnvalue;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /* -------------------------------------------------------------*
  98.  * Constructors for TLZBitmap                    *
  99.  *--------------------------------------------------------------*/
  100.  
  101. /* TLZBitmap is a Class derived from TBitmap that brings with it new construtors:
  102.  
  103.    TLZBitmap(HINSTANCE instance, TResID resID, const char *NameInArchiv=NULL);
  104.  
  105.       A TLZBitmap-Object constructed with this constructor will load
  106.       a LZH-Compressed BMP-File from the Archiv.
  107.  
  108.    TLZBitmap(LPLZHEAD SourcePtr, const char *NameInArchiv=NULL);
  109.  
  110.       A TLZBitmap-Object constructed with this constructor will decompress
  111.       the memory-Block "SourcePtr" and create a TBitmap-Object for it
  112. */
  113.  
  114.  
  115.  
  116.  
  117. // ---- TLZBitmap from Resource -----------------------------
  118.  
  119. TLZBitmap::TLZBitmap(HINSTANCE Instance, TResId resID, const char *NameInArchiv)
  120.     :TBitmap( GimmeABitmapHandle( Instance, resID, NameInArchiv ), AutoDelete )
  121. //    :TBitmap ( LoadLZHResource(instance, resID, NameInArchiv, sizeof(BITMAPFILEHEADER) ), AutoDelete )
  122. { // that's all - Folks!
  123. }
  124.  
  125.  
  126.  
  127. // ---- TLZBitmap from Memory Block -------------------------
  128.  
  129. TLZBitmap::TLZBitmap(LPLZHEAD SourcePtr, const char *NameInArchiv)
  130.     :TBitmap ( TLZDib(SourcePtr, NameInArchiv) )
  131. { // that's all - Folks!
  132. }
  133.  
  134.  
  135.  
  136. // ---- Get a Handle, depending if Archiv is found -------
  137. HBITMAP TLZBitmap::GimmeABitmapHandle(HINSTANCE Instance, TResId resID, const char *NameInArchiv)
  138. { HBITMAP returnvalue;
  139.  
  140.   // ---- First test if we have a LZH-Archiv ---------------
  141.   returnvalue = LoadLZHBitmap(Instance, resID, NameInArchiv );
  142.  
  143.   // ---- If this did not work, try the normal BITMAP type--
  144.   if (!returnvalue)
  145.     returnvalue = ::LoadBitmap( Instance, resID);
  146.  
  147.   return returnvalue;
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.